package com.miyu.system.controller.opensystem.rule;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.miyu.common.pojo.system.SysRule;
import com.miyu.system.service.rule.SysRuleService;
import com.miyu.system.utils.enumeration.Result;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 系统规则
 *
 * @author longm
 * @date 2022/10/30
 */
@RestController
@RequestMapping(value = "/sys-rule")
public class SysRuleController {

    @Resource
    private SysRuleService ruleService;
    /**
     * 查询规则
     * @param param 规则名称
     * @return {@link JSONArray}
     */
    @RequestMapping(value = "querySysRule")
    public JSONArray querySysRule(@RequestBody JSONObject param) {
        return ruleService.querySysRule(param);
    }

    /**
     * 删除系统规则
     * @param params 参数
     * @return {@link JSONObject}
     */
    @RequestMapping(value = "delSysRule")
    public JSONObject delSysRule(@RequestBody JSONArray params) {
        return ruleService.delSysRule(params);
    }

    /**
     * 编辑系统规则
     * @param param 参数
     * @return {@link JSONObject}
     */
    @RequestMapping("editSysRule")
    public JSONObject editSysRule(@RequestBody JSONObject param) {
        SysRule rule = ruleService.editSysRule(param);
        return Result.getInfoByCode("10001");
    }

    /**
     * 缓存物系统规则
     * @param ruleId 参数
     * @return {@link SysRule}
     */
    @RequestMapping(value = "getSysRuleById",method = RequestMethod.GET)
    public SysRule getSysRuleById(String ruleId) {
        return ruleService.getSysRuleById(ruleId);
    }

    /**
     * 系统规则字典数据
     * @return {@link JSONArray}
     */
    @RequestMapping("getSysRule")
    public JSONArray getSysRule() {
        return ruleService.getSysRule();
    }
}
